package com.zhengdongzulin.zuke.base

import androidx.lifecycle.ViewModel
import com.zhengdongzulin.zuke.parser.code
import com.zhengdongzulin.zuke.parser.msg
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.data.GlobalInfo

/**
 * jeff
 * 2021-03-29 11:02:50
 */
open class BaseViewModel : ViewModel() {
    var mShareViewModel: GlobalInfo? = null
    var mCurrentPage = 1
    var mPageTotal = 1
    var mPageSize = 10

    /**
     * 请求失败或错误默认处理
     */
    fun <T> assignment(t: Throwable, liveData: StateLiveData<T>) {
        t.printStackTrace()
        when (t.code) {
            500 -> {
                liveData.postEmpty()
                liveData.errMsg = t.msg
            }
            else -> {
                liveData.postError()
                liveData.errMsg = t.msg
            }
        }
    }
}